package com.global.base;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.global.Constants;
import org.springframework.context.i18n.LocaleContextHolder;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Date Utility Class used to convert Strings to Dates and Timestamps
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 *         Modified by <a href="mailto:dan@getrolling.com">Dan Kibler </a>
 *         to correct time pattern. Minutes should be mm not MM (MM is month).
 * @author zly601436        
 */
public final class DateUtil extends Util {
	
	private DateUtil(){};
	
    private static Log log = LogFactory.getLog(DateUtil.class);

	/**
	 * 日期分隔符，从系统参数中获取，window系统中日期分隔符只有三个"./-"
	 */
	public static String DATE_SEPERATOR = "./-";
	/**
	 * 时间分隔符，从系统参数中获取，window系统时间分隔符只有":"
	 */
	public static String TIME_SEPERATOR = ":";
    /**
     * 时间格式码
     */
    public static final String TIME_PATTERN = "HH" + TIME_SEPERATOR + "mm";
	/**
	 * 合法的日期格式清单
	 */
	private static List<String> VALIDITY_DATE_PATTERN_LIST;
	/**
	 * 合法的时间格式清单
	 */
	private static List<String> VALIDITY_TIME_PATTERN_LIST;
	/**
	 * 合法的日期时间格式清单
	 */
	private static List<String> VALIDITY_DATETIME_PATTERN_LIST;
	
	/**
	 * 初始化默认值的日期格式例子、时间格式例子、日期时间格式例子
	 */
	static
	{	    
	    VALIDITY_DATE_PATTERN_LIST = new ArrayList<String>();
	    if(StringUtils.isNotBlank(DATE_SEPERATOR)){
	    	VALIDITY_DATE_PATTERN_LIST.add("20110101");
			for(char c : DATE_SEPERATOR.toCharArray()){
				String str = "2011" + String.valueOf(c) + "1" + String.valueOf(c) + "12";
				VALIDITY_DATE_PATTERN_LIST.add(str);
			}
	    }	    
	    
	    VALIDITY_TIME_PATTERN_LIST = new ArrayList<String>();
	    if(StringUtils.isNotBlank(TIME_SEPERATOR)){
			for(char c : TIME_SEPERATOR.toCharArray()){
				String str = "01" + String.valueOf(c) + "12" + String.valueOf(c) + "52";
				VALIDITY_TIME_PATTERN_LIST.add(str);
			}
	    }
	    
	    VALIDITY_DATETIME_PATTERN_LIST = new ArrayList<String>();
	    if(VALIDITY_DATE_PATTERN_LIST.size()>0 && VALIDITY_TIME_PATTERN_LIST.size()>0){
	    	for(String dateP : VALIDITY_DATE_PATTERN_LIST){
	    		for(String timeP : VALIDITY_TIME_PATTERN_LIST){
					String str = dateP + " " + timeP;
					VALIDITY_DATETIME_PATTERN_LIST.add(str);
	    		}
			}
	    }
    }
	
	/**
	 * 获取合法的日期参考格式数组
	 * @return List<String> 
	 */
	public static List<String> getValidityDatePatternList(){		
		return VALIDITY_DATE_PATTERN_LIST;
	}
	
	/**
	 * 获取合法的时间参考格式数组
	 * @return List<String> 
	 */
	public static List<String> getValidityTimePatternList(){		
		return VALIDITY_TIME_PATTERN_LIST;
	}
	
	/**
	 * 获取合法的日期时间参考格式数组
	 * @return List<String> 
	 */
	public static List<String> getValidityDateTimePatternList(){		
		return VALIDITY_DATETIME_PATTERN_LIST;
	}
	
    /**
     * Return default datePattern (yyyy/MM/dd)
     * <br/>返回当前系统中的默认日期格式
     * @return a string representing the date pattern on the UI
     */
    public static String getDatePattern() {
    	//获取当前环境中的Locale
        Locale locale = LocaleContextHolder.getLocale();
        String defaultDatePattern;
        try {
        	ResourceBundle bundle = ResourceBundle.getBundle(Constants.BUNDLE_KEY, locale);
            defaultDatePattern = bundle.getString("date.format");
        } catch (MissingResourceException mse) {
            defaultDatePattern = "yyyy/MM/dd";
        }

        return defaultDatePattern;
    }

    public static String getDateTimePattern() {
        return DateUtil.getDatePattern() + " HH:mm:ss.SSS";
    }

    /**
     * This method generates a string representation of a date/time
     * in the format you specify on input
     *
     * @param aMask the date pattern the string is in
     * @param strDate a string representation of a date
     * @return a converted Date object
     * @throws ParseException when String doesn't match the expected format
     * @see java.text.SimpleDateFormat
     */
    public static Date convertStringToDate(String aMask, String strDate) throws ParseException {
        SimpleDateFormat df;
        Date date;
        df = new SimpleDateFormat(aMask);

        if (log.isDebugEnabled()) {
            log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'");
        }

        try {
            date = df.parse(strDate);
        } catch (ParseException pe) {
            //log.error("ParseException: " + pe);
            throw new ParseException(pe.getMessage(), pe.getErrorOffset());
        }

        return (date);
    }

    /**
     * This method returns the current date time in the format:
     * MM/dd/yyyy HH:MM a
     *
     * @param theTime the current time
     * @return the current date/time
     */
    public static String getTimeNow(Date theTime) {
        return getDateTime(TIME_PATTERN, theTime);
    }

    /**
     * This method returns the current date in the format: MM/dd/yyyy
     *
     * @return the current date
     * @throws ParseException when String doesn't match the expected format
     */
    public static Calendar getToday() throws ParseException {
        Date today = new Date();
        SimpleDateFormat df = new SimpleDateFormat(getDatePattern());

        // This seems like quite a hack (date -> string -> date),
        // but it works ;-)
        String todayAsString = df.format(today);
        Calendar cal = new GregorianCalendar();
        cal.setTime(convertStringToDate(todayAsString));

        return cal;
    }

    /**
     * This method generates a string representation of a date's date/time
     * in the format you specify on input
     *
     * @param aMask the date pattern the string is in
     * @param aDate a date object
     * @return a formatted string representation of the date
     * @see java.text.SimpleDateFormat
     */
    public static String getDateTime(String aMask, Date aDate) {
        SimpleDateFormat df = null;
        String returnValue = "";

        if (aDate == null) {
            log.warn("aDate is null!");
        } else {
            df = new SimpleDateFormat(aMask);
            returnValue = df.format(aDate);
        }

        return (returnValue);
    }

    /**
     * This method generates a string representation of a date based
     * on the System Property 'dateFormat'
     * in the format you specify on input
     *
     * @param aDate A date to convert
     * @return a string representation of the date
     */
    public static String convertDateToString(Date aDate) {
        return getDateTime(getDatePattern(), aDate);
    }

    /**
     * This method converts a String to a date using the datePattern
     *
     * @param strDate the date to convert (in format MM/dd/yyyy)
     * @return a date object
     * @throws ParseException when String doesn't match the expected format
     */
    public static Date convertStringToDate(final String strDate) throws ParseException {
        return convertStringToDate(getDatePattern(), strDate);
    }
    
    
    /**
     * 判断字符串是否日期（时间）类型，
     * <br/>严格按照pattern进行验证，则不符合pattern的字符串不合法
     * <br/>如果格式为"yyyyMMdd"，则2010-12-32，2010-2-31，2010/12/31，2010-12/23等自字符串均不合法
	 * @param dateStr 日期(时间)字符串
	 * @param pattern 格式
	 * @param inLocale  区域
	 * @return true 表示输入的字符串dateStr为某种格式format的日期型字符串
	 * @throws Exception
	 */
	public static boolean isDateStr(String dateStr, String pattern, Locale inLocale){
		errorMessage = "";
		
		if(StringUtils.isNotBlank(dateStr) && StringUtils.isNotBlank(pattern)){
			Date date = getDate(dateStr, pattern, inLocale);
			
			return (date==null ? false : true);
		}else{
			errorMessage = "日期字符串以及格式码均不能为空, 否则无法判断";
		}
		
		return false;
	}
	
	/**
     * 判断字符串是否日期（时间）类型，
     * <br/>严格按照pattern进行验证，则不符合pattern的字符串不合法
     * <br/>如果格式为"yyyyMMdd"，则2010-12-32，2010-2-31，2010/12/31，2010-12/23等自字符串均不合法
	 * @param dateStr
	 * @param pattern
	 * @return true 表示输入的字符串dateStr为某种格式format的日期型字符串
	 * @throws Exception
	 */
	public static boolean isDateStr(String dateStr, String pattern){	
		return isDateStr(dateStr, pattern, null);
	}
	
    /**
     * 判断字符串是否日期（时间）类型，
     * <br/>严格按照pattern进行验证，则不符合pattern的字符串不合法
     * <br/>如果格式为"yyyyMMdd"，则2010-12-32，2010-2-31，2010/12/31，2010-12/23等自字符串均不合法
     * @param dateString 需要转换为Date的字符串 
     * @param pattern 格式码
     * @param inLocale 区域码, 如果为空，则取默认值的
     * @return boolean 
     */
	public final static Date getDate(String dateString, String pattern, Locale inLocale) {
		Date newDate = null;
		errorMessage = "";
		
		if(StringUtils.isBlank(dateString) || StringUtils.isBlank(pattern)){
			errorMessage = "参数dateString与pattern均不能为空";
		}else{
			DateFormat dateFormat;
			try {
				if(inLocale!=null){
					dateFormat = new SimpleDateFormat(pattern, inLocale);
				}else{
					dateFormat = new SimpleDateFormat(pattern);
				}
				
				dateFormat.setLenient(false);  //要严格限制
				newDate = dateFormat.parse(dateString);
			}catch (IllegalArgumentException e) {
				errorMessage = "pattern【" + pattern + "】不合法，原因：" + e.toString();
			}catch (ParseException e) {
				errorMessage = "字符串【" + dateString + "】与pattern【" + pattern + "】不匹配，原因：" + e.toString();
			}
		}		
		
		return newDate;
	}
	
    /**
     * 将字符串转换成日期（时间）类型，
     * <br/>严格按照pattern进行验证，则2010-12-32，2010-2-31等自字符串均不合法，且不符合pattern的字符串不合法
     * @param dateString 需要转换为Date的字符串 
     * @param pattern 格式码
     * @return boolean 
     */
	public final static Date getDate(String dateString, String pattern) {
		return getDate(dateString, pattern, null);
	}

    /**
     * 根据输入的年、月、日获取到某个日期
     * <br/><span style="color">采用严格转换方式</span>
     * @param year 年
     * @param month 月
     * @param date 日
     * @return
     */
	public final static Date getDate(int year, int month, int date) {
		errorMessage = "";

		if(year>0 && month>0 && date>0){
			try {
				Calendar calendar = Calendar.getInstance();
				//月是从0开始的，即0-11表示1月到12月
				calendar.set(year, month - 1, date);
				calendar.setLenient(false); // 严格转换

				return calendar.getTime();
			} catch (java.lang.IllegalArgumentException e) {
				errorMessage = "输入的年【" + year + "】月【" + month + "】日【" + date + "】不正确：" + e.toString();
			}
		}else{
			errorMessage = "输入的年【" + year + "】月【" + month + "】日【" + date + "】中不能出现负数";
		}
		
		return null;
	}
	
	/**
	 * 返回Timestamp
	 * @param date 需要转换的日期
	 * @return
	 */
	public final static java.sql.Timestamp getTimestamp(Date date){
		return date!=null ? new java.sql.Timestamp(date.getTime()) : null;
	}
	
	/**
	 * 返回Timestamp
	 * @param value 需要转换的对象
	 * @return
	 */
	public final static java.sql.Timestamp getTimestamp(Object value){
		
		try {
			if (value == null){
				return null;
			}
			
			DateFormat IN_TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy/MM/dd H:mm:ss.SSS");
			
			if (value instanceof java.sql.Timestamp){
				return (java.sql.Timestamp) value;
			}else if (value instanceof Date){
				Date newDate = (Date)value;
				return new java.sql.Timestamp(newDate.getTime());
			}else if (value instanceof java.sql.Date){
				java.sql.Date newDate = (java.sql.Date)value;
				return new java.sql.Timestamp(newDate.getTime());
			}else if (value instanceof String) {
				if ("".equals((String)value)){
					return null;
				}else{
					return new java.sql.Timestamp(IN_TIMESTAMP_FORMAT.parse((String) value).getTime());
				}
			}

			return new java.sql.Timestamp(IN_TIMESTAMP_FORMAT.parse(value.toString()).getTime());

		} catch (ParseException pe) {
			errorMessage = pe.getMessage();

			return null;
		}        
	}
	
	/**
     * Convert an Object to a Time, without an Exception
     */
    public static java.sql.Time getTime( Object value )
    {
        try
        {
        	if( value == null ) {
        		return null;        
        	}
        	
        	DateFormat IN_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");            
        	
            if( value instanceof java.sql.Time ){
            	return (java.sql.Time)value;
            }else if (value instanceof Date){
				Date newDate = (Date)value;
				return new java.sql.Time(newDate.getTime());
			}else if (value instanceof java.sql.Date){
				java.sql.Date newDate = (java.sql.Date)value;
				return new java.sql.Time(newDate.getTime());
			}else if( value instanceof String ){
                if( "".equals( (String)value ) ) {
                	return null;
                }else{
                	return new java.sql.Time( IN_TIME_FORMAT.parse( (String)value ).getTime() );
                }
            }
                    
            return new java.sql.Time( IN_TIME_FORMAT.parse( value.toString() ).getTime() );
        
        } catch( ParseException pe ) {
        	errorMessage = pe.getMessage();
            return null;
        }
    }
    
    /**
     * 将输入的日期剔除时间再返回
     * @param date
     * @return Date
     */
    public static Date getDateTrimTime(Date date) {
    	if(date!=null){
    		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd ");
    		String logEntry = formatter.format(date);

    		try {
    			date = formatter.parse(logEntry);
    		} catch (ParseException exc) {
    			exc.printStackTrace();
    		}
    	}    	
		
		return date;
    }
    
    /**
	 *  参照日期格式将日期转换为字符串
	 * @param date
	 * @param pattern 例如： yyyy/MM/dd HH:mm:ss
	 * @return
	 */
	public static String getDateToStr(Date date, String pattern) {
		errorMessage = "";

		try {
			if (date != null && StringUtils.isNotBlank(pattern)) {
				DateFormat df = new SimpleDateFormat(pattern);
				return df.format(date);
			} else {
				errorMessage = "日期与日期格式均不能为空，否则无法转换";
			}
		} catch (Exception e) {
			errorMessage = "将日期类型或者日期时间类型转换为指定格式的字符串时，出现异常，可能原因是格式(" + pattern	+ ")不正确，异常为：" + e.toString();
		}

		return "";
	}
	
    /**
	 *  参照时间戳格式将时间戳类型转换为字符串
	 * @param date
	 * @param pattern  例如： yyyy/MM/dd HH:mm:ss.SSS
	 * @return
	 */
	public static String getTimestampToStr(java.sql.Timestamp timestamp, String pattern) {
		errorMessage = "";

		try {
			if (timestamp != null && StringUtils.isNotBlank(pattern)) {
				DateFormat df = new SimpleDateFormat(pattern);
				return df.format(timestamp);
			} else {
				errorMessage = "时间戳格式均不能为空，否则无法转换";
			}
		} catch (Exception e) {
			errorMessage = "将时间戳类型转换为指定格式的字符串时，出现异常，可能原因是格式(" + pattern	+ ")不正确，异常为：" + e.toString();
		}

		return "";
	}
	
    /**
	 *  参照时间格式将时间转换为字符串
	 * @param date
	 * @param pattern 例如：HH:mm:ss.SSS
	 * @return
	 */
	public static String getTimeToStr(java.sql.Time time, String pattern) {
		errorMessage = "";

		try {
			if (time != null && StringUtils.isNotBlank(pattern)) {
				DateFormat df = new SimpleDateFormat(pattern);
				return df.format(time);
			} else {
				errorMessage = "时间格式均不能为空，否则无法转换";
			}
		} catch (Exception e) {
			errorMessage = "将时间转换为指定格式的字符串时，出现异常，可能原因是格式(" + pattern	+ ")不正确，异常为：" + e.toString();
		}

		return "";
	}
	
	/**
	 * 返回日期加减N天后的日期
	 * @param date 
	 * @param offset 
	 * @return 返回N（可以是负数）天后的日期
	 */
	public static Date getNewDate(Date date, int offset) {
		errorMessage = "";
		
		if(date!=null){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.DAY_OF_YEAR, (calendar.get(Calendar.DAY_OF_YEAR) + offset));
			
			return calendar.getTime();
		}else{
			return null;
		}
	} 
	
	/**
	 * 返回日期加减N秒后的日期时间
	 * @param date
	 * @param offset 
	 * @return 返回N（可以是负数）秒后的日期时间
	 */
	public static Date getNewSecond(Date date, int offset) {
		errorMessage = "";
		
		if(date!=null){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.MILLISECOND, (calendar.get(Calendar.MILLISECOND) + offset*1000));

			return calendar.getTime();
		}else{
			return null;
		}
	} 
	
	/**
	 * 返回日期加减N月后的日期
	 * @param date
	 * @param offset 
	 * @return 返回N（可以是负数）月后的日期时间
	 */
	public static Date getNewMonth(Date date, int offset) {
		errorMessage = "";
		
		if(date!=null){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(Calendar.MONTH, offset);

			return calendar.getTime();
		}else{
			return null;
		}
	} 
	
	/**
	 * 返回日期加减N年后的日期
	 * @param date
	 * @param offset 
	 * @return 返回N（可以是负数）年后的日期
	 */
	public static Date getNewYear(Date date, int offset) {
		errorMessage = "";
		
		if(date!=null){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(Calendar.YEAR, offset);

			return calendar.getTime();
		}else{
			return null;
		}
	}
	
	
	/**
	 * <span style="color:red">目前只支持字符串由数字与分隔符组成的串
	 * <br/>如果字符串全部由数字组成，那么该串的长度必须为8，例如：20110101</span>

	 * <br/>
	 * <br/>如果字符串全部为数字（首字符必须大于0），且长度为8，则再按照格式"yyyyMMdd"进行验证
	 * <br/>如果字符串不全部为数字，则再按照数字与分隔符【./-】组合的方式再验证一次
	 * <br/>
	 * <br/>例如：系统设置的日期格式为2011/01/12，很显然，字符串“2011-01-12”不符合系统设置的日期格式，但按照分隔符分隔后，通过得到的年【2011】、月【01】
	 * 日【12】却可以组成合法的日期，所以验证通过
	 * <br/>
	 * <br/>合法的日期格式分为两种：1》日期中不带分隔符：例如【20110201、20110201 02:03:04】，对于这种情况的字符串，日期部分的长度必须为8位
	 *                             2》日期中带分隔符（window操作系统中提到的分隔符）：例如【2011-1-1、2011-01-1、2011-1-01、2011/1/1 1:12:23】
	 *                             
     * <br/>
     * <br/>合法的日期格式，可以通过方法{@link getValidityDatePatternList}获得                
	 * @param dateStr 需要转换的日期（时间）
	 * @return date不为空，表明转换成功
	 */
	public static Date getStrToDate(String dateStr)
	{
		errorMessage = "";

		Date newDate = null;

		/**
		 * 首字符必须为大于0的数字，且最后一个字符必须为数字
		 */
		if(StringUtils.isNotBlank(dateStr) && 
				!dateStr.startsWith("0") && NumberUtil.isCanToInteger(dateStr.substring(0, 1)) && 
				NumberUtil.isCanToInteger(dateStr.substring(dateStr.length()-1))){
			/**
			 * 如果日期字符串中只包含数字，表明该字符串很可能就是不带分隔符的日期格式字符串
			 */
			if(NumberUtil.isPositiveIntegerPattern(dateStr)){
				if(dateStr.length()==8 && !dateStr.startsWith("0") && NumberUtil.isCanToInteger(dateStr)){
					newDate = getDate(dateStr, "yyyyMMdd");
				}
			}else{
			    /**
			     * 如果日期字符串中包含数字以外的字符，表明有两种情况：1》该字符串很可能是包含时间的日期时间格式字符串  2》该字符串中包含分隔符
			     * 将日期字符串【例如：2011/12/12, 23:45:34】拆分成两段
			     */
				List<String> splitStr = StringUtil.splitStr(dateStr, " ");
				if(splitStr.size()==1){
					/**
					 * 拆分后数组为1，则按照不含时间来处理
					 */
					if(StringUtils.isNotBlank(DATE_SEPERATOR)){
						for(char c : DATE_SEPERATOR.toCharArray()){
				    		List<String> newStrList = StringUtil.splitStr(dateStr, "\\" + String.valueOf(c));
							if(newStrList!=null && newStrList.size()==3){
								String year = newStrList.get(0);
								String month = newStrList.get(1);
								String day = newStrList.get(2);
								
								if(NumberUtil.isCanToInteger(year) && NumberUtil.isCanToInteger(month) && NumberUtil.isCanToInteger(day)){
									if(Integer.parseInt(month)<=12 && Integer.parseInt(month)>=1){
										if(Integer.parseInt(day)>=1 && Integer.parseInt(day)<=31){
											newDate = getDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
											if(newDate!=null){
												newDate = getDateTrimTime(newDate);
												break;
											}
										}
									}
								}
							}
				    	}
					}
				}else if(splitStr.size()==2){
					/**
					 * 拆分后数组为2，则按照日期时间来处理
					 */						
					String date1 = splitStr.get(0);  //获取日期部分
					String time1 = splitStr.get(1);  //获取时间部分
					
					if(NumberUtil.isPositiveIntegerPattern(date1)){
						if(date1.length()==8 && NumberUtil.isCanToInteger(date1)){
							for(char t : TIME_SEPERATOR.toCharArray()){
								List<String> newStrList1 = StringUtil.splitStr(time1, "\\" + String.valueOf(t));
								if(newStrList1!=null && newStrList1.size()==3){
									String hour = StringUtils.leftPad(newStrList1.get(0), 2, "0");
									String minute = StringUtils.leftPad(newStrList1.get(1), 2, "0");
									String second = StringUtils.leftPad(newStrList1.get(2), 2, "0");
									
									if(NumberUtil.isCanToInteger(hour) && NumberUtil.isCanToInteger(minute) && NumberUtil.isCanToInteger(second)){
										String tempStr = date1 + " " + hour + String.valueOf(t) + minute + String.valueOf(t) + second;
										String tempPattern = "yyyyMMdd" + " HH" + String.valueOf(t) + "mm" + String.valueOf(t) + "ss";
										newDate = getDate(tempStr, tempPattern);
										if(newDate!=null){
											break;
										}
									}
								}
							}	
						}
					}else{							
						if(StringUtils.isNotBlank(DATE_SEPERATOR) && StringUtils.isNotBlank(TIME_SEPERATOR)){
							for(char c : DATE_SEPERATOR.toCharArray()){
								List<String> newStrList = StringUtil.splitStr(date1, "\\" + String.valueOf(c));
								if(newStrList!=null && newStrList.size()==3){
									String year = newStrList.get(0);
									String month = StringUtils.leftPad(newStrList.get(1), 2, "0");
									String day = StringUtils.leftPad(newStrList.get(2), 2, "0");
									
									if(NumberUtil.isCanToInteger(year) && NumberUtil.isCanToInteger(month) && NumberUtil.isCanToInteger(day)){
										if(Integer.parseInt(month)<=12 && Integer.parseInt(month)>=1 && Integer.parseInt(day)<=31 && Integer.parseInt(day)>=1){
											for(char t : TIME_SEPERATOR.toCharArray()){
												List<String> newStrList1 = StringUtil.splitStr(time1, "\\" + String.valueOf(t));
												if(newStrList1!=null && newStrList1.size()==3){
													String hour = StringUtils.leftPad(newStrList1.get(0), 2, "0");
													String minute = StringUtils.leftPad(newStrList1.get(1), 2, "0");
													String second = StringUtils.leftPad(newStrList1.get(2), 2, "0");
													
													if(NumberUtil.isCanToInteger(hour) && NumberUtil.isCanToInteger(minute) && NumberUtil.isCanToInteger(second)){
														String tempStr = year + String.valueOf(c) + month + String.valueOf(c) + day + " " + hour + String.valueOf(t) + minute + String.valueOf(t) + second;
														String tempPattern = "yyyy" + String.valueOf(c) + "MM" + String.valueOf(c) + "dd" + " HH" + String.valueOf(t) + "mm" + String.valueOf(t) + "ss";
														newDate = getDate(tempStr, tempPattern);
														if(newDate!=null){
															break;
														}
													}
												}
											}										
										}
									}
								}
					    	}
						}
					}
				}
			}
		}		
		
		if(newDate==null){
			List<String> splitStr = StringUtil.splitStr(dateStr, " ");
			if(splitStr.size()==2){
				errorMessage = "日期时间字符串【" + dateStr + "】不合法，正确的日期格式请参考：" + VALIDITY_DATETIME_PATTERN_LIST + "中的任意一种格式书写";
			}else{
				errorMessage = "日期字符串【" + dateStr + "】不合法，正确的日期格式请参考：" + VALIDITY_DATE_PATTERN_LIST + "中的任意一种格式书写";
			}
		}
		
		return newDate;
	}
	
	public static void main(String[] args){
		Date strToDate = DateUtil.getStrToDate("2011-12-08 22:00:13");
		log.info(strToDate);
		
		java.sql.Timestamp dd = new java.sql.Timestamp(new Date().getTime());
		log.info(dd);
	}
}
